<?php

namespace App\Clients\MeiTuan;

use Exception;
use GuzzleHttp\Exception\GuzzleException;

class BillingReconciliationAllocationSettlementBills extends MeiTuanClient
{

    /**
     * 初步处理数据
     * @return void
     */
    public function handleData(): void
    {
        try{
//            var_dump($this->contents);
//            exit();
//            if($this->contents["code"] != 0){
//                $this->contents = [
//                    "total"=>0,
//                    "pageItems"=>[],
//                    "sum"=>[],
//                ];
//            }
            //$this->contents = json_decode($this->contents,true);
            if($this->contents["code"] == 402){
                $this->contents = false;
                return;
            }
            $this->contents = $this->contents["code"] != 0 ? [
                "total"=>0,
                "pageItems"=>[],
                "sum"=>[],
            ] : [
                "total"=>$this->contents["data"]["page"]["totalCount"],
                "pageItems"=>$this->contents["data"]["records"],
                "sum"=>$this->contents["sum"],
            ];
        }catch(Exception $e){
            var_dump($this->contents);
            throw $e;
        }
    }

    /**
     * @throws GuzzleException
     */
    public function execute($queryData): BillingReconciliationAllocationSettlementBills
    {
        return $this->post("https://pos.meituan.com/web/api/v1/billing-reconciliation/allocation-settlement-bills?yodaReady=h5&csecplatform=4&csecversion=3.2.0",$queryData);
    }
}
